package com.yc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yc.bean.FoodBean;
import com.yc.mapper.FoodMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zwei
 * @create 2024-10-07 15:28
 */
@Service
//@Transactional
public class FoodBizImpl implements FoodBiz{
    private static FoodMapper foodMapper;
    private String cacheName="好吃点餐网";       //缓存名称
    @Autowired
    public void setFoodMapper(FoodMapper foodMapper) {
        FoodBizImpl.foodMapper = foodMapper;
    }

    /**
     * 查询所有菜品
     * @return
     */
//    @Cacheable(cacheNames = "${cacheName}",key = "'all'")
    @Override
    public List<FoodBean> getFood() {
        QueryWrapper<FoodBean>qw=new QueryWrapper<>();
        qw.eq("disabled",0);
        List<FoodBean>list=foodMapper.selectList(qw);
        return list;
    }
//    @Cacheable(cacheNames = "${cacheName}",key = "#id")
    @Override
    public List<FoodBean> getfoodbyid(Integer id) {
        QueryWrapper<FoodBean> qw=new QueryWrapper<>();
        qw.eq("id",id).eq("disabled",0);
        List<FoodBean> list = foodMapper.selectList(qw);
        return list;
    }
}
